import os, sys
try:
  import fitz
except:
  os.system("pip3 install --user pymupdf")
import fitz

def main(a):
  s= fitz.open(a)
  s2 = os.path.basename(a).rsplit('.', 1)[0]
  if not os.path.exists(s2):
    os.mkdir(s2)
  for i in range(s.page_count):
    s3=s[i].get_pixmap()
    s3.save(os.path.join(s2, "%s.png" %(i+1)), "png")
    print("\t%i / %i" %(i+1, s.page_count), end='\r')
  print()

if __name__ == "__main__":
  for i in sys.argv[1:]:
    main(i.strip('\'\"\\').rstrip("/"))
